package org.example.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.example.pojo.User;
import org.example.pojo.UserDTO;

@Mapper
public interface UserMapper {

    /**
     * 登录
     * @param user
     * @return
     */
    @Select("select * from user where username=#{username} and password=#{password}")
    User login(UserDTO user);

    /**
     * 获取用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id=#{id}")
    User getInfo(int id);

    /**
     * 获取用户列表
     * @param status
     * @param inputName
     * @return
     */
    Page<User> list(String status, String inputName);

    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into user(username,password,nickname,sex,user_pie,status,create_time,update_time,phone) " +
            "values(#{username},#{password},#{nickname},#{sex},#{userPie},#{status},#{createTime},#{updateTime},#{phone})")
    void add(User user);

    /**
     * 修改用户
     * @param user
     */
    void update(User user);

    /**
     * 删除用户
     * @param id
     */
    @Delete("delete from user where id=#{id}")
    void delete(Integer id);

    /**
     * 根据用户名获取用户信息
     * @param username
     * @return
     */
    @Select("select * from user where username=#{username}")
    User getByUsername(String username);

    /**
     * 根据id获取用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id=#{id}")
    User getById(Integer id);

    /**
     * 修改用户头像
     * @param avatarUrl
     * @param id
     */
    @Update("update user set user_pie=#{avatarUrl},update_time=now() where id=#{id}")
    void updateAvatar(String avatarUrl, int id);

    /**
     * 修改用户密码
     * @param newPwd
     */
    @Update("update user set password=#{newPwd},update_time= now() where id=#{id}")
    void updatePwd(String newPwd,int id);
}
